package com.xbongbong.saas.script.tempenum;

import com.xbongbong.paas.enums.ComboTypeEnum;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.BatchFlowBillEnum;
import com.xbongbong.saas.enums.business.FlowSubFormEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 批次流水
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/19
 * @since v1.0
 */
@Getter
public enum TempBatchFlowBillEnum {
    // 显示模板字段
    SERIAL_NO(BatchFlowBillEnum.SERIAL_NO),
    NAME(BatchFlowBillEnum.NAME),
    SPECIFICATION(BatchFlowBillEnum.SPECIFICATION),
    BATCH(BatchFlowBillEnum.BATCH),
    PRODUCE_DATE(BatchFlowBillEnum.PRODUCE_DATE),
    GUARANTEE_PERIOD(BatchFlowBillEnum.GUARANTEE_PERIOD),
    EXPIRE_DATE(BatchFlowBillEnum.EXPIRE_DATE),
    TIME(BatchFlowBillEnum.TIME),
    SHEET_NO(BatchFlowBillEnum.SHEET_NO),
    TYPE(BatchFlowBillEnum.TYPE),
    BUSINESS_ID(BatchFlowBillEnum.BUSINESS_ID),
    WAREHOUSE_ID(BatchFlowBillEnum.WAREHOUSE_ID),
    UNIT(BatchFlowBillEnum.UNIT),
    OUT_IN_RECORD(BatchFlowBillEnum.OUT_IN_RECORD),
    REMAINING_STOCK(BatchFlowBillEnum.REMAINING_STOCK),

    ;

    private BatchFlowBillEnum anEnum;

    TempBatchFlowBillEnum(BatchFlowBillEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempBatchFlowBillEnum> getAllEnum() {
        List<TempBatchFlowBillEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
    }

    public static void initProduceDate(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
    }

    public static void initExpireDate(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType(DateTimeEnum.TIME.getType());
    }

    public static void initOutInRecord(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity num = InitExplainsHelper.setField(FlowSubFormEnum.QUANTITY.getAttr(), FlowSubFormEnum.QUANTITY.getAttrName(), FlowSubFormEnum.QUANTITY.getSaasAttr(), FlowSubFormEnum.QUANTITY.getFieldType(), FlowSubFormEnum.QUANTITY.getSetType(), FlowSubFormEnum.QUANTITY.getShowType(), FlowSubFormEnum.QUANTITY.getEditHide(), 0);
        num.setParentAttr(OUT_IN_RECORD.getAnEnum().getAttr());
        items.add(num);
        FieldAttrEntity cost = InitExplainsHelper.setField(FlowSubFormEnum.COST.getAttr(), FlowSubFormEnum.COST.getAttrName(), FlowSubFormEnum.COST.getSaasAttr(), FlowSubFormEnum.COST.getFieldType(), FlowSubFormEnum.COST.getSetType(), FlowSubFormEnum.COST.getShowType(), FlowSubFormEnum.COST.getEditHide(), 0);
        cost.setParentAttr(OUT_IN_RECORD.getAnEnum().getAttr());
        items.add(cost);
        FieldAttrEntity totalCost = InitExplainsHelper.setField(FlowSubFormEnum.COST_TOTAL.getAttr(), FlowSubFormEnum.COST_TOTAL.getAttrName(), FlowSubFormEnum.COST_TOTAL.getSaasAttr(), FlowSubFormEnum.COST_TOTAL.getFieldType(), FlowSubFormEnum.COST_TOTAL.getSetType(), FlowSubFormEnum.COST_TOTAL.getShowType(), FlowSubFormEnum.COST_TOTAL.getEditHide(), 0);
        totalCost.setParentAttr(OUT_IN_RECORD.getAnEnum().getAttr());
        items.add(totalCost);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    public static void initRemainingStock(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity num = InitExplainsHelper.setField(FlowSubFormEnum.QUANTITY.getAttr(), FlowSubFormEnum.QUANTITY.getAttrName(), FlowSubFormEnum.QUANTITY.getSaasAttr(), FlowSubFormEnum.QUANTITY.getFieldType(), FlowSubFormEnum.QUANTITY.getSetType(), FlowSubFormEnum.QUANTITY.getShowType(), FlowSubFormEnum.QUANTITY.getEditHide(), 0);
        num.setParentAttr(REMAINING_STOCK.getAnEnum().getAttr());
        items.add(num);
        FieldAttrEntity cost = InitExplainsHelper.setField(FlowSubFormEnum.COST.getAttr(), FlowSubFormEnum.COST.getAttrName(), FlowSubFormEnum.COST.getSaasAttr(), FlowSubFormEnum.COST.getFieldType(), FlowSubFormEnum.COST.getSetType(), FlowSubFormEnum.COST.getShowType(), FlowSubFormEnum.COST.getEditHide(), 0);
        cost.setParentAttr(REMAINING_STOCK.getAnEnum().getAttr());
        items.add(cost);
        FieldAttrEntity totalCost = InitExplainsHelper.setField(FlowSubFormEnum.COST_TOTAL.getAttr(), FlowSubFormEnum.COST_TOTAL.getAttrName(), FlowSubFormEnum.COST_TOTAL.getSaasAttr(), FlowSubFormEnum.COST_TOTAL.getFieldType(), FlowSubFormEnum.COST_TOTAL.getSetType(), FlowSubFormEnum.COST_TOTAL.getShowType(), FlowSubFormEnum.COST_TOTAL.getEditHide(), 0);
        totalCost.setParentAttr(REMAINING_STOCK.getAnEnum().getAttr());
        items.add(totalCost);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.CUSTOM.getAlias());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }

    public static void initType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setComboType(ComboTypeEnum.CUSTOM.getType());
        List<XbbRefTypeEnum> subList = Arrays.asList(XbbRefTypeEnum.CONTRACT_OUTSTOCK, XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK, XbbRefTypeEnum.OTHER_OUTSTOCK, XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK, XbbRefTypeEnum.WORK_ORDER_OUTSTOCK,
                XbbRefTypeEnum.PURCHASE_INSTOCK, XbbRefTypeEnum.REFUND_INSTOCK, XbbRefTypeEnum.OTHER_INSTOCK, XbbRefTypeEnum.PRODUCTION_INSTOCK, XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK, XbbRefTypeEnum.ORI_STOCK);
        List<ItemPoJo> items = new ArrayList<>();
        subList.forEach(item -> {
            ItemPoJo itemPoJo = new ItemPoJo(item.getName(), item.getCode(), false);
            items.add(itemPoJo);
        });
        fieldAttrEntity.setItems(items);
    }
}
